<template>
	<view class="content">
		<my-bar><block slot="content">关于我们</block></my-bar>
		<view class="about">
			<view class="about-content">
				<view class="qrcode">
					<!-- #ifdef APP-PLUS -->
					<image src="/static/logo.png" @longtap="save"></image>
					<!-- #endif -->
					<!-- #ifdef H5-->
					<image src="/static/logo.png"></image>
					<!-- #endif -->
					<!--#ifdef MP-->
					<image src="/static/logo.png"></image>
					<!-- #endif -->
					<text class="tip">好学生呀</text>
				</view>
				<view class="desc">
					一款o2o线上线下互动教学，便于教师监控、提高学生学习乐趣的微信小程序。
					主要有签到（远程实时签到、线下课堂签到）、远程遥控点名、在线弹幕、在线云笔（在线人数、云笔记弹幕）记这四大模块。
					远程实时签到、NFC碰一碰签到和iBeacon蓝牙签到主要帮助教师线上线下考勤管理及教学监控等。
					远程遥控点名和在线弹幕帮助教师活跃氛围，提高学生学习的乐趣。在线云笔记则是帮助同学进行课前预习和课后复习，
					促进学习的氛围，从而提高学习效率、增加学习兴趣的目的。
				</view>
				<view class="source">
					<view class="title"></view>
					<view class="source-list">
						<view class="source-cell">
							<text space="nbsp"></text>
							<text></text>
						</view>
						<view class="source-cell">
							<text space="nbsp"></text>
							<text @click="openLink" class="link">{{ sourceLink }}</text>
						</view>
					</view>
				</view>
				<!-- #ifdef APP-PLUS -->
				<button class="cu-btn bg-green lg " @click="share">分享</button>
				<!-- #endif -->
			</view>
			<!-- #ifdef APP-PLUS -->
			<view class="version">当前版本：{{ version }}</view>
			<!-- #endif -->
		</view>
	</view>
</template>

<script>
import util from '@/common/util'
export default {
	data() {
		return {
			providerList: [],
			version: '',
			sourceLink: ''
		};
	},
	// #ifdef APP-PLUS
	onLoad() {
		var that = this;
		plus.runtime.getProperty(plus.runtime.appid, wgtinfo => {
			//console.log(JSON.stringify(wgtinfo));
			//console.log(wgtinfo.version); //应用版本号
			that.version = wgtinfo.version;
		});

		uni.getProvider({
			service: 'share',
			success: e => {
				let data = [];
				for (let i = 0; i < e.provider.length; i++) {
					switch (e.provider[i]) {
						case 'weixin':
							data.push({
								name: '分享到微信好友',
								id: 'weixin'
							});
							data.push({
								name: '分享到微信朋友圈',
								id: 'weixin',
								type: 'WXSenceTimeline'
							});
							break;
						case 'qq':
							data.push({
								name: '分享到QQ',
								id: 'qq'
							});
							break;
						default:
							break;
					}
				}
				this.providerList = data;
			},
			fail: e => {
				console.log('获取登录通道失败' + JSON.stringify(e));
			}
		});
	},
	// #endif
	methods: {
		// #ifdef APP-PLUS
		save() {
			uni.showActionSheet({
				itemList: ['保存图片到相册'],
				success: () => {
					plus.gallery.save(
						'/static/logo.png',
						function() {
							uni.showToast({
								title: '保存成功',
								icon: 'none'
							});
						},
						function() {
							uni.showToast({
								title: '保存失败，请重试！',
								icon: 'none'
							});
						}
					);
				}
			});
		},
		share(e) {
			if (this.providerList.length === 0) {
				uni.showModal({
					title: '当前环境无分享渠道!',
					showCancel: false
				});
				return;
			}
			let itemList = this.providerList.map(function(value) {
				return value.name;
			});
			uni.showActionSheet({
				itemList: itemList,
				success: res => {
					uni.share({
						provider: this.providerList[res.tapIndex].id,
						scene: this.providerList[res.tapIndex].type && this.providerList[res.tapIndex].type === 'WXSenceTimeline' ? 'WXSenceTimeline' : 'WXSceneSession',
						type: 0,
						title: '欢迎使用好学生',
						summary: '好学生是一个专为老师打造的教学分享平台，提高课堂的趣味性',
						imageUrl: '/static/logo.png',
						href: util.baseUrl+'/'+this.$store.state.base.appName+'.apk',
						success: res => {
							console.log('success:' + JSON.stringify(res));
						},
						fail: e => {
							uni.showModal({
								content: e.errMsg,
								showCancel: false
							});
						}
					});
				}
			});
		},
		// #endif
		openLink() {
			if (plus) {
				plus.runtime.openURL(this.sourceLink);
			} else {
				window.open(this.sourceLink);
			}
		}
	}
};
</script>

<style>
image {
	width: 360upx;
	height: 360upx;
}

.about {
	flex-direction: column;
	flex: 1;
}

.about-content {
	flex: 1;
	padding: 30upx;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}

.qrcode {
	display: flex;
	align-items: center;
	flex-direction: column;
}

.qrcode .tip {
	margin-top: 20upx;
}
.tip{
	font-size: 34rpx;
}
.desc {
	margin-top: 30upx;
	text-indent: 25px;
	display: block;
	line-height: 55rpx;
	font-size: 30rpx;
}

.code {
	color: #e96900;
	background-color: #f8f8f8;
}

button {
	width: 100%;
	margin-top: 40upx;
}

.version {
	height: 80upx;
	line-height: 80upx;
	justify-content: center;
	text-align: center;
	color: #ccc;
}

.source {
	margin-top: 30upx;
	flex-direction: column;
}

.source-list {
	flex-direction: column;
}

.link {
	color: #007aff;
}
</style>
